/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BotRidder;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
 * @author user1
 */
public class BotRidder extends MIDlet implements CommandListener {

    private Map1 mapa;
    private Form form ;
    private Command exitCommand;
    private Command m1;
    private Command m2;
    private Command m3;
    private Command m4;
    public Display pantalla;
    public Bot botti;
    StringItem stringItem1;
    /*private List menu;*/
    //private Command activar;
    
    
    public BotRidder(){
        pantalla = Display.getDisplay(this);
        mapa = new Map1(this);
        botti = new Bot();
        /*menu = new List("MENU",List.IMPLICIT);
        menu.insert(0,"EJECUTAR",null);
        menu.insert(1,"PROGRAMAR", null);
        menu.addCommand(salir);
        menu.setCommandListener(this);*/
    }
    
    public Command getExitCommand() {
        if (exitCommand == null) {
            // write pre-init user code here
            exitCommand = new Command("Exit", Command.EXIT, 0);
            // write post-init user code here
        }
        return exitCommand;
    }
    public StringItem getStringItem1() {
        if (stringItem1 == null) {
            // write pre-init user code here
            stringItem1 = new StringItem("hola", null);
            // write post-init user code here
        }
        return stringItem1;
    }
    
    public void startApp() {
        pantalla.setCurrent(getForm());
        
        
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    public void salir(){
        destroyApp(false);
        notifyDestroyed();
    }
    
    public Display getDisplay() {
        return Display.getDisplay(this);
    }
public Command getM1() {
        if (m1 == null) {
            // write pre-init user code here
            m1 = new Command("Ok1", Command.OK, 0);
            // write post-init user code here
        }
        return m1;
    }
    
public Command getM2() {

        if (m2 == null) {
            // write pre-init user code here
            m2 = new Command("Ok1", Command.OK, 0);
            // write post-init user code here
        }
        return m2;
    }

public Command getM3() {

        if (m3 == null) {
            // write pre-init user code here
            m3 = new Command("m3", Command.OK, 0);
            // write post-init user code here
        }
        return m3;
    }
public Command getM4() {

        if (m4 == null) {
            // write pre-init user code here
            m4 = new Command("Ok1", Command.OK, 0);
            // write post-init user code here
        }
        return m4;
    }



    public void commandAction(Command command, Displayable displayable){
        if (displayable == form) {
            if (command == exitCommand) {
                // write pre-action user code here
                salir();
                // write post-action user code here
            } else if (command == m1) {
                // write pre-action user code here
                //pantalla.setCurrent(mapa);
                
                switchDisplayable(null, mapa);
                // write post-action user code here
            
        }else if (command == m2) {
                // write pre-action user code here
                //pantalla.setCurrent(mapa);
                
                switchDisplayable(null, mapa);
                // write post-action user code here
            
        }else if (command == m4) {
                // write pre-action user code here
                //pantalla.setCurrent(mapa);
                
                switchDisplayable(null, mapa);
                // write post-action user code here
            
        }
            
            /*else if (displayable == form1) {
            if (command == exitCommand) {
                // write pre-action user code here
                switchDisplayable(null, form);
                // write post-action user code here
            }else if (command == m3) {
                // write pre-action user code here
                //pantalla.setCurrent(mapa);
                
                switchDisplayable(null, getForm1());
                // write post-action user code here
            
        }
        }*/
        
    }}
    
      public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
        // write pre-switch user code here
        Display display = getDisplay();
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }
        // write post-switch user code here
    }
          public Form getForm() {
        if (form == null) {
            // write pre-init user code here
            form = new Form("form", new Item[]{});
            form.addCommand(getExitCommand());
            form.addCommand(getM1());
            form.addCommand(getM2());
  //          form.addCommand(getM3());
            form.addCommand(getM4());
            form.setCommandListener(this);
            // write post-init user code here
        }
        return form;
    }


}
